requireJS(['constant', 'site', 'handlebars'], function (constant, site, Handlebars) {



    var isOpenId;

    function EmailFun() {
        // 查询邮箱接口调用
        site.send({
                url: 'manager/selectEmailService.do',
                //async:false
                callback: function (data) {
                    data = JSON.parse(data);
                    if (data.type == '1') {
                        isOpenId = data.content.is_open;
                        emailData.is_open = isOpenId;
                        if (isOpenId == 1) {
                            $('.slide-btn').children().eq(0).addClass('D-queding');
                            $('.slide-btn').children().eq(1).removeClass('D-queding');

                        } else {
                            $('.slide-btn').children().eq(1).addClass('D-queding');
                            $('.slide-btn').children().eq(0).removeClass('D-queding');
                        }
                        $("#server").val(data.content.server);
                        $("#port").val(data.content.port);
                        $("#send_mail").val(data.content.send_mail)
                        $("#e_name").val(data.content.e_name)
                        $("#e_pwd").val(data.content.e_pwd)
                        $("#test_mail").val(data.content.test_mail)
                    }
                }
            }
        );
    }

    EmailFun();

    // 是否按钮切换
    $('.slide-btn').children().each(function () {
        $(this).click(function () {
            $(this).addClass("D-queding");
            isOpenId = $(this).index() + 1;
            emailData.is_open = isOpenId;
            $(this).siblings('span').removeClass("D-queding");
        })
    });
    //发送邮箱接口
    var emailData = {
        is_open: isOpenId
    };

// 修改邮箱
    $('.send-email').click(function () {
        constant.fn.formParam('#emialPort_box', emailData);
        site.send({
                url: 'manager/send.do',
                //async:false
                data: emailData,
                callback: function (data) {
                    data = JSON.parse(data);
                    if(data.type == '1'){
                        constant.fn.Message("T",data.msg);
                    }
                    else{
                        constant.fn.Message("F",data.msg);
                    }
                }
            }
        )
    });
    // 邮箱接口提交
    $('.submit-mail').click(function () {
        constant.fn.formParam('#emialPort_box', emailData);
        site.send({
                url: 'manager/updateEmailService.do',
                //async:false
                data: emailData,
                callback: function (data) {
                    data = JSON.parse(data);
                    if (data.type == '1') {
                        EmailFun();
                        constant.fn.Message('T', data.msg)
                    } else {
                        constant.fn.Message('F', data.msg)

                    }

                }
            }
        )
    });
});
